<template>
  <el-button v-if="downloadBtn" class="footerBtn" type="primary" icon="el-icon-download" @click="downloadFile">{{ btnName
  }}</el-button>
</template>
<script>
import downloadApi from "@/api/download";
import { mymixin } from "@/utils/mixin";
export default {
  name: "Button",
  components: {},
  data () {
    return {
    };
  },
  props: {
    downloadBtn: {
      type: Boolean,
      default: false
    },
    btnName: {
      type: String,
      default: '按钮'
    },
    apiName: {
      type: String,
      default: ''
    },
    searchObj: {
      type: Object,
      default: () => ({})
    }
  },
  mixins: [mymixin],
  mounted () {
  },
  methods: {
    downloadFile () {
      console.log(downloadApi, this.apiName && downloadApi[this.apiName])
      if (this.apiName && downloadApi[this.apiName]) {
        downloadApi[this.apiName](this.searchObj).then(res => {
          this.getFileNameAndDownload(res)
          console.log('成功导出')
        })
      } else {
        console.error("请在'/api/download/index.js'下配置对应的导出接口！");
      }
    }
  }
};
</script>
<style scoped lang="scss">
.footerBtn {
  position: absolute;
  left: 0px;
  bottom: 0px;
}
</style>
